import asyncio

import pymongo
from pymongo import MongoClient

from config import settings
from .basic import mdb
from .es import connect_to_es, close_es_connect
from .mongo import connect_to_mongo, close_mongo_connection

client = MongoClient(settings.dsn)
col_inst = client["kexie"]["institution"]
activity_col = client["kexie"]["activity"]
institution_col = client["kexie"]["institution"]
activity_register_col = client["kexie"]["activity_register"]
col_person = client["kexie"]["alumni"]


async def initial_ioservice():
    await asyncio.gather(
        connect_to_mongo(),
        connect_to_es()
    )


async def close_ioservice():
    await asyncio.gather(
        close_mongo_connection(),
        close_es_connect()
    )


async def rebuild_compound_index():
    """"""
    col_person.create_index([("mike", pymongo.DESCENDING)],
                               background=True)

